package com.zzyl.controller.web;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingPlanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 护理计划表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-08-15
 */
@RestController
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;

    //分页条件查询
    @GetMapping("/nursing/plan/search")
    public ResponseResult getByPage(String name, Integer status,
                                    @RequestParam(defaultValue = "1")Integer pageNum,
                                    @RequestParam(defaultValue = "10")Integer pageSize){
        PageResponse<NursingPlan> page=nursingPlanService.getByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(page);
    }

    //新增
    @PostMapping("/nursing/plan")
    public ResponseResult save(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.saveNursingPlan(nursingPlanDto);
        return ResponseResult.success();
    }

    //主键查询
    @GetMapping("nursing/plan/{id}")
    public ResponseResult findById(@PathVariable("id")Long id){
        NursingPlanVo nursingPlanVo=nursingPlanService.findById(id);
        return ResponseResult.success(nursingPlanVo);
    }

    //修改
    @PutMapping("/nursing/plan/{id}")
    public ResponseResult update(@PathVariable("id")Long id,@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.updatePlan(nursingPlanDto);
        return ResponseResult.success();
    }

    //删除
    @DeleteMapping("/nursing/plan/{id}")
    public ResponseResult deleteById(@PathVariable("id")Long id){
        nursingPlanService.deleteById(id);
        return ResponseResult.success();
    }

    //启用/禁用
    @PutMapping("nursing/{id}/status/{status}")
    public ResponseResult updateStauts(@PathVariable Long id,
                                       @PathVariable Integer status){
        NursingPlan nursingPlan=new NursingPlan();
        nursingPlan.setId(id);
        nursingPlan.setStatus(status);
        nursingPlanService.updateById(nursingPlan);
        return ResponseResult.success();
    }
}
